package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 forEach遍历集合
 1.8Jdk
 */
public class ForEachDem {
    public static void main(String[] args) {
        Map<String,Integer>map=new HashMap<>();
        map.put("语文", 101);
        map.put("数学", 75);
        map.put("英语", 7);
        map.put("政治", 70);
        map.put("历史", 60);
        map.put("地理", 80);
        Set<String>keySet=map.keySet();
        keySet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        keySet.forEach( s -> System.out.println(s));
        Collection<Integer>value=map.values();
        value.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });
        value.forEach(integer->System.out.println(integer));


        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println(s+","+integer);
            }
        });
        map.forEach((s,v)-> System.out.println(s+","+v));
    }
}
